﻿//双击事件
var CustomDbClick = function () {
    /*var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    document.getElementById("EditUIWindow").src = operationUrl + "/AutoEditUI.aspx?action=view&r=" + Math.random() + "&entity=" + const_EditEntity + "&id=" + record.getData("MajorStudentId");
    document.getElementById("yui-gen9-button").style.display = "none";
    YAHOO.example.container.dialog1.show();
    var editwindow = document.getElementById("EditUIWindow");
    if (editwindow) {
    setTimeout(editwindow.contentWindow.$("#form1").SeControlReadOnly(), 200);
    }*/

    /*var elist = [];
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    elist.push(record.getData("MajorStudentId"));
    ids = elist;
    document.getElementById("EditUIWindow").src = "../Crm/MajorStudentGroup.aspx?r=" + Math.random() + "&entity=CrmMajorStudent_G";
    document.getElementById("yui-gen9-button").style.display = "block";
    YAHOO.example.container.dialog1.show();*/
}

//学员分团
var fnCustomAdd = function () {
    if (fkey == "" || fkey == "00000000-0000-0000-0000-000000000000") {
        alert("请选择左侧课程期数菜单!");
    } else {
        window.parent.$("#tabs").tabs('close', '学员分团');
        var pagetitle = "学员分团";
        parent.addTabs(pagetitle, '../Crm/StudentSign.aspx?r=' + Math.random() + '&title=' + encodeURI(pagetitle) + '&id=' + fkey);
        parent.NeedRefreshPage = this;
    }
    //    var list = this.mDataTable.getRecordSet()._records;
    //    var elist = [];
    //    for (var i = 0; i < list.length; i++) {
    //        if (list[i]._oData["iSun_Selected"] == true) {
    //            elist.push(list[i]._oData["MajorStudentId"]);
    //        }
    //    }
    //    ids = elist;
    //    if (ids.length > 0) {
    //        document.getElementById("EditUIWindow").src = "../Crm/MajorStudentGroup.aspx?r=" + Math.random() + "&entity=CrmMajorStudent_G";
    //        document.getElementById("yui-gen9-button").style.display = "block";
    //        YAHOO.example.container.dialog1.show();
    //        /*document.getElementById("EditUIWindow").src = "../Extend/AutoEditUI.aspx?r=" + Math.random() + "&entity=CrmMajorStudent_G";
    //        document.getElementById("yui-gen9-button").style.display = "block";
    //        YAHOO.example.container.dialog1.show();*/
    //    }
    //    else {
    //        alert('您没有选中任何项');
    //    }
}
//设置辅导员
var fnSetAssistance = function () {
    if (fkey == "" || fkey == "00000000-0000-0000-0000-000000000000") {
        alert("请选择左侧课程期数菜单!");
    } else {
        document.getElementById("EditUIWindow").src = "../Crm/StudentSetAssistance.aspx?r=" + Math.random() + "&id=" + fkey;
        document.getElementById("yui-gen9-button").style.display = "block";
        YAHOO.example.container.dialog1.show();
    }
}
//设置团长
var fnSetManager = function () {
    var list = this.mDataTable.getRecordSet()._records;
    var managerId; //团长ID
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            managerId = list[i]._oData["MajorStudentId"];
            break;
        }
    }
    if (managerId == undefined) {
        alert('请选择学员');
        return;
    }
    var url = "http://" + this.location.host + "/Extend/AjaxData/DataProcessin.aspx";
    YAHOO.util.Connect.asyncRequest('POST', url + "?flag=1&action=Update&entity=V_CrmMajorStudent&id=" + managerId, callback);
}
//签到
var fnSignIn = function () {
    var list = this.mDataTable.getRecordSet()._records;
    var StudentId = []; //学员ID
    var MajorId = []; //大课ID
    var IsTrain = []; //是否复训
    var IsDecision = []; //是否决策人
    var CustomerId = []; //客户ID
    var OrderProductId = []; //订单产品ID
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            MajorId.push(list[i]._oData["ID"]);
            StudentId.push(list[i]._oData["MajorStudentId"]);
            IsTrain.push(list[i]._oData["IsTrain"]);
            IsDecision.push(list[i]._oData["IsDecision"]);
            CustomerId.push(list[i]._oData["CustomerId"]);
            OrderProductId.push(list[i]._oData["OrderProductID"]);
        }
    }
    ids = StudentId;
    if (ids.length == 0) {
        alert("您没有选中任何学员,无法签到!");
    }
    var url = "http://" + this.location.host + "/Extend/AjaxData/DataProcessin.aspx";
    for (var i = 0; i < ids.length; i++) {
        var vStr = ids[i] + "," + MajorId[i] + "," + IsTrain[i] + "," + IsDecision[i] + "," + CustomerId[i] + "," + OrderProductId[i];
        YAHOO.util.Connect.asyncRequest('POST', url + "?flag=1&action=Update&entity=V_CrmMajorStudent1&id=" + vStr, callback1);
    }
}
//自定义新增方法
var fnAddStudent = function () {
    window.parent.$("#tabs").tabs('close', '新增大课学员');
    var pagetitle = "新增大课学员";
    parent.addTabs(pagetitle, '../Crm/Deliver/AddDeliverMajor.aspx?r=' + Math.random() + '&flag=0&entity=CrmDeliverMajor&title=' + encodeURI(pagetitle));
    parent.NeedRefreshPage = this;
}

var responseSuccess = function (res) {
    try {
        var str = res.responseText;
        if (str == "1") {
            alert('设置成功');
            ReLoadData();
        }
        else {
            alert('设置失败');
        }
    } catch (e) {
    }
    finally {
    }
};
var responseFailure = function (error) {
    alert("数据错误：" + error.statusText);
}
var callback = {
    success: responseSuccess,
    failure: responseFailure
};
var responseSuccess1 = function (res) {
    try {
        var str = res.responseText;
        if (str == "1") {
            alert('签到成功');
            ReLoadData();
        }
        else {
            alert(str);
        }
    } catch (e) {
    }
    finally {
    }
};
var responseFailure1 = function (error) {
    alert("数据错误：" + error.statusText);
}
var callback1 = {
    success: responseSuccess1,
    failure: responseFailure1
};
var showMessage = function () {
    alert('签到成功');
}


//自定义修改学员基本信息方法fnEditStudent
var fnCustomEdit = function () {
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData["MajorStudentId"]);
        }
    }
    ids = elist;
    if (ids.length == 0) {
        alert('请选择学员');
        return;
    } else if (ids.length >= 2) {
        alert('您选择了多行记录,修改请单行选择!');
        return;
    } else {
        if (Y.util.Dom.getViewportHeight() < 401) {
            //alert(Y.util.Dom.getViewportHeight());
            SetMaxDWH(YAHOO.example.container.dialog1);
        }
        var recordID = myDataTable.getSelectedRows()[0];
        record = myDataTable.getRecord(recordID);
        document.getElementById("EditUIWindow").src = "http://" + this.location.host + "/Extend/AutoEditUI.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id=" + record.getData("MajorStudentId");
        document.getElementById("yui-gen9-button").style.display = "block";
        SetDWH(500, 450, YAHOO.example.container.dialog1);
        YAHOO.example.container.dialog1.show();
    }
}
//自定义查询
var fnCustomQueryRe = function (condition) {
    if (fkey != '00000000-0000-0000-0000-000000000000')
        const_CustomCondition = condition + " and (ProductLayoutID='" + fkey + "')";
    else
        const_CustomCondition = condition;
    RefreshData();
}
//格式化列
var formatDecision = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0") {
        elCell.innerHTML = "否";
    } else if (sData == "1") {
        elCell.innerHTML = "是";
    } else {
        elCell.innerHTML = "";
    }
}
var formatTrain = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0") {
        elCell.innerHTML = "否";
    } else if (sData == "1") {
        elCell.innerHTML = "是";
    } else {
        elCell.innerHTML = "";
    }
}
var formatIsSignIn = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0") {
        elCell.innerHTML = "否";
    } else if (sData == "1") {
        elCell.innerHTML = "是";
    } else {
        elCell.innerHTML = "";
    }
}
var formatSignIn = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0001-01-01 " || sData == "1900-01-01 ") {
        elCell.innerHTML = "";
    } else {
        elCell.innerHTML = sData;
    }
}